package com.belizer.demo.stream;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Demo {
    public static void main(String[] args) {
//        IntStream intStream = IntStream.rangeClosed(1,10);
//        int sum = intStream.sum();
//        System.out.println("sum->" + sum);


//        List<Integer> integerList = Stream.iterate(0, n -> n + 2).collect(Collectors.toList());
//        System.out.println("integerList->" + integerList);

//        Stream.generate(Math::random).forEach(System.out::println);
        //准备数据 1-100
        Stream<Integer> integerStream = Stream.iterate(1, a -> a + 1).limit(10000000).parallel();

        long s1 = System.currentTimeMillis();
        Optional<Integer> any = integerStream.findAny();
        System.out.println("findAny消耗时间->" + ((System.currentTimeMillis())-s1));

    }
}
